package org.xlh.springboot;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.xlh.springboot.bean.Vip;
import org.xlh.springboot.service.VipService;

import java.util.List;

//通过@MapperScan指定要扫描的mapper接口所在的包
@MapperScan("org.xlh.springboot.repository")
@SpringBootApplication
public class Springboot312MybatisApplication {

	public static void main(String[] args) {
		ConfigurableApplicationContext run = SpringApplication.run(Springboot312MybatisApplication.class, args);

		//获取service对象
		VipService vipService = run.getBean(VipService.class);

		//调用service对象的方法
		vipService.save(new Vip("jack2", "1001", "1990-01-01"));
		vipService.save(new Vip("lucy2", "1002", "1990-01-02"));

		List<Vip> vipList = vipService.findAll();
		vipList.forEach(vip -> System.out.println(vip));

		//关闭容器
		run.close();
	}

}
